home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Format 1994 October
/
Macformat17.cdr
/
Shareware City
/
Developers
/
Kamprath's CDEF Pack ƒ
/
CDEF Sampler Program ƒ
/
sampler.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-12
|
6KB
|
318 lines
/*****
* bullseye.c
*
* A simple demonstration program to play with the debugger
*
*
*****/
#include "samplerMenus.h"
#include "samplerWindow.h"
#include "samplerControls.h"
#include "number_picker.h"
extern WindowPtr samplerWindow;
extern ControlHandle rocketCntl, timeButtonCntl, timeCntl, dateCntl, numberCntl;
extern ControlHandle squarePlain, squareBold, squareLarge;
extern Rect dragRect;
SysEnvRec gMac;
void InitMacintosh(void);
void HandleMouseDown (EventRecord *theEvent);
void HandleEvent(void);
void HandleOSEvent(EventRecord *event);
void DoActivateWindow( Boolean activating );
/****
* InitMacintosh()
*
* Initialize all the managers & memory
*
****/
void InitMacintosh(void)
{
MaxApplZone();
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
SysEnvirons(curSysEnvVers, &gMac);
if (gMac.systemVersion < 0x0700)
ExitToShell();
}
/* end InitMacintosh */
/****
* HandleMouseDown (theEvent)
*
* Take care of mouseDown events.
*
****/
void HandleMouseDown (EventRecord *theEvent)
{
WindowPtr theWindow;
int windowCode = FindWindow (theEvent->where, &theWindow);
switch (windowCode)
{
case inSysWindow:
SystemClick (theEvent, theWindow);
break;
case inMenuBar:
AdjustMenus();
HandleMenu(MenuSelect(theEvent->where));
break;
case inDrag:
if (theWindow == samplerWindow)
DragWindow(samplerWindow, theEvent->where, &dragRect);
break;
case inContent:
if (theWindow == samplerWindow)
{
short cntlPart;
Point clickPt = theEvent->where;
ControlHandle foundCntl;
if (theWindow != FrontWindow())
SelectWindow(samplerWindow);
else
{
GlobalToLocal(&clickPt);
cntlPart = FindControl(clickPt, samplerWindow, &foundCntl);
if (cntlPart)
{
if (( foundCntl == rocketCntl)||( foundCntl == timeButtonCntl ))
{
if (cntlPart = TrackControl( foundCntl, clickPt, 0 ))
{
if ( foundCntl == rocketCntl)
{
SysBeep(20);
}
else if (foundCntl == timeButtonCntl)
{
SetCtlValue( timeButtonCntl, !GetCtlValue(timeButtonCntl));
if (GetCtlValue( timeButtonCntl))
{
HiliteControl(timeCntl, 0);
HiliteControl(dateCntl, 0);
HiliteControl(numberCntl, 0);
}
else
{
HiliteControl(timeCntl, 255);
HiliteControl(dateCntl, 255);
HiliteControl(numberCntl, 255);
}
}
}
}
else
{
if ( foundCntl == dateCntl)
{
SetCtlValue( timeCntl, 0 );
HandleDateCDEFClick(clickPt);
}
else if ( foundCntl == timeCntl)
{
SetCtlValue( dateCntl, 0 );
HandleTimeCDEFClick(clickPt);
}
else if ( foundCntl == numberCntl)
{
if (cntlPart = TrackControl( foundCntl, clickPt, NumCDEFProc ))
{
/* do nothing because NumCDEFProc() handles it */
}
}
else if ((foundCntl == squarePlain)
||(foundCntl == squareBold)
||(foundCntl == squareLarge))
{
if (cntlPart = TrackControl( foundCntl, clickPt, NumCDEFProc ))
{
SetCtlValue( foundCntl, !GetCtlValue( foundCntl ));
}
}
}
}
else
{
SetCtlValue( timeCntl, 0 );
SetCtlValue( dateCntl, 0 );
}
}
}
break;
case inGoAway:
if (theWindow == samplerWindow &&
TrackGoAway(samplerWindow, theEvent->where))
HideWindow(samplerWindow);
break;
}
}
/* end HandleMouseDown */
/****
* HandleEvent()
*
* The main event dispatcher. This routine should be called
* repeatedly (it handles only one event).
*
*****/
void HandleEvent(void)
{
int ok;
EventRecord theEvent;
ControlHandle curCntl;
HiliteMenu(0);
SystemTask (); /* Handle desk accessories */
ok = GetNextEvent (everyEvent, &theEvent);
if (ok)
switch (theEvent.what)
{
case mouseDown:
HandleMouseDown(&theEvent);
break;
case keyDown:
case autoKey:
if ((theEvent.modifiers & cmdKey) != 0)
{
AdjustMenus();
HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
}
break;
case updateEvt:
BeginUpdate(samplerWindow);
DrawSampleWindow(((WindowPeek) samplerWindow)->hilited);
EndUpdate(samplerWindow);
break;
case activateEvt:
if (theEvent.modifiers & activeFlag)
{
DoActivateWindow( true );
}
else
{
DoActivateWindow( false );
}
break;
case osEvt:
HandleOSEvent(&theEvent);
break;
}
}
/* end HandleEvent */
void HandleOSEvent(EventRecord *event)
{
Boolean inBackground;
switch ((event->message >> 24) & 0x00FF) { /* High byte of message */
case suspendResumeMessage:
inBackground = (event->message & resumeFlag) == 0;
if (FrontWindow())
{
DoActivateWindow( !inBackground);
}
if (!inBackground)
{
SetCursor( &arrow );
}
break;
case mouseMovedMessage:
break;
}
}
void DoActivateWindow( Boolean activating )
{
ControlHandle curCntl;
if (activating)
{
HiliteControl(rocketCntl, 0);
HiliteControl(timeButtonCntl, 0);
if (GetCtlValue( timeButtonCntl))
{
HiliteControl(timeCntl, 0);
HiliteControl(dateCntl, 0);
HiliteControl(numberCntl, 0);
}
else
{
HiliteControl(timeCntl, 255);
HiliteControl(dateCntl, 255);
HiliteControl(numberCntl, 255);
}
HiliteControl(squarePlain, 0);
HiliteControl(squareBold, 0);
HiliteControl(squareLarge, 0);
}
else
{
curCntl = ((WindowPeek)samplerWindow)->controlList;
while (curCntl)
{
HiliteControl(curCntl, 255);
curCntl = (*curCntl)->nextControl;
}
}
}
/*****
* main()
*
* This is where everything happens
*
*****/
main()
{
InitMacintosh();
SetUpMenus();
SetUpWindow();
for (;;)
HandleEvent();
}
/* end main */